const C = require('memory-cache')
const Food = require('./food')

module.exports = {
  add: (user_id,food_id,status = 0,time = new Date().toString()) => {
    const orders = C.get('orders')
    orders.push({
      id: orders.length,
      user_id,food_id,status,time,
    })
    C.put('orders',orders)
  },
  all: () => C.get('orders'),
  all_by_shop_id: shop_id => {
    const all_food_ids = Food.all_foods_by_shop(shop_id).map(food => food.id)

    return C.get('orders').filter(o => {
      return all_food_ids.find(id => id == o.food_id) != null
    })
  }
}